package com.hd123.rumba.gwt.widget.client.grid;

import com.google.gwt.user.client.ui.TextBox;
import com.hd123.rumba.gwt.widget.client.Util;

public class StringEditor extends TextBox implements CellEditor {

  public StringEditor() {
    super();
    super.setStyleName("DxGrid-CellEditor");
  }

  public void activate(DxGrid grid, int row, int col, String text, String width, String height,
      boolean readOnly) {
    super.setText(text);
    grid.setWidget(row, col, this);
    super.setReadOnly(readOnly);
    super.setWidth("100%");
    super.setHeight("97%");
    Util.focusTextBox(this);
  }

  public boolean isLeftKeyToLeave() {
    return isReadOnly() || getCursorPos() == 0;
  }

  public boolean isRightKeyToLeave() {
    return isReadOnly() || super.getText() == null || getCursorPos() == super.getText().trim().length();
  }

  public String getValue() {
    return getText();
  }

  public void setValue(String value) {
    setText(value);
  }

}
